package com.tehui.adapter;

import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.tehui.R;
import com.tehui.bean.BrandData;
import com.tehui.utils.ui.UiUtils;

import java.util.List;

import static com.tehui.app.MyApplication.IS_TAOKE;

/**
 * Created by jasmine on 2017/4/12.
 */

public class CommodityListAdapter extends BaseAdapter {
    private       List<BrandData.ResultBean> result;
    private final RequestOptions             options;

    public CommodityListAdapter(List<BrandData.ResultBean> result) {
        this.result = result;
        if (IS_TAOKE) {
            options = new RequestOptions().centerCrop().placeholder(R.drawable.sd);
        } else {
            options = new RequestOptions().centerCrop().placeholder(R.drawable.sds);
        }
    }

    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(UiUtils.getContext(), R.layout.item_brand_layout, null);
            holder = new ViewHolder();
            holder.img = (ImageView) convertView.findViewById(R.id.img);
            holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle);
            holder.money = (TextView) convertView.findViewById(R.id.money);
            holder.oldMoney = (TextView) convertView.findViewById(R.id.oldMoney);
            holder.oldMoney.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            holder.num = (TextView) convertView.findViewById(R.id.num);
            holder.reduce = (TextView) convertView.findViewById(R.id.reduce);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Glide.with(UiUtils.getContext()).load(result.get(position).Pic).apply(options).transition(new DrawableTransitionOptions().crossFade(300)).into(holder.img);

        holder.tvTitle.setText(result.get(position).D_title);
        holder.money.setText("¥" + result.get(position).Price + "元");
        holder.oldMoney.setText("¥" + result.get(position).Org_Price + "元");
        holder.num.setText(result.get(position).Sales_num + "人已买");
        holder.reduce.setText("减" + result.get(position).Quan_price + "元");
        return convertView;
    }

    public static class ViewHolder {
        ImageView img;
        TextView  tvTitle;
        TextView  money;
        TextView  oldMoney;
        TextView  num;
        TextView  reduce;
    }
}


